package cc.messcat.service.fupin;

import cc.messcat.common.model.Pager;
import cc.messcat.common.service.BaseServiceImpl;
import cc.messcat.common.util.StringUtil;
import cc.messcat.dao.area.AreaDao;
import cc.messcat.dao.fupin.FamilyDao;
import cc.messcat.dao.fupin.PoorFamilyDao;
import cc.messcat.entity.area.Area;
import cc.messcat.entity.fupin.Family;
import cc.messcat.entity.fupin.PoorFamily;
import cc.messcat.entity.fupin.PoorFamilyHistory;
import cc.messcat.entity.helpPerson.HelpPerson;
import cc.messcat.entity.system.ApplicationProperties;
import cc.messcat.entity.system.McUser;
import cc.messcat.entity.system.TableMaintenance;
import cc.messcat.entity.vo.PoorFamilyVo;
import cc.messcat.service.area.AreaService;
import cc.messcat.service.system.UserService;
import cc.messcat.util.Collections;
import cc.messcat.util.*;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.*;

@Service
public class PoorFamilyServiceImpl extends BaseServiceImpl<PoorFamily>implements PoorFamilyService {
	private static Logger log = LoggerFactory.getLogger(PoorFamilyServiceImpl.class);
	@Autowired
	public UserService userService;

	@Autowired
	private PoorFamilyDao poorFaDao;

	@Autowired
	private AreaService areaService;
	
	@Autowired
	private AreaDao areaDao;

	@Autowired
	private FamilyDao familyDao;

	@Value("#{ configProperties['web.name'] }")
	private String projectName;

	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory;
	
	@Autowired
	private CacheManager manager;

	@Autowired
    private TableMaintenance tableMaintenance;
	
	private Long fid;

	@Override
	public Pager<PoorFamily> getPager(int pageNo, int pageSize) {
		Map map = new HashMap<>();
		String hql = "from PoorFamily where isDel= :isDel ORDER BY addTime DESC";
		map.put("isDel", "0");
		return this.poorFaDao.getPagerByHql(pageNo, pageSize, hql, map);
	}

	@Override
	public Long addPoorFamily(PoorFamily poorFamily) {
		return poorFaDao.save1(poorFamily);
	}

	@Override
	public void modifyPoorFamily(PoorFamily poorFamily) {
		this.poorFaDao.update(poorFamily);

	}

	/**
	 * 获取新实体类的通用方法
	 * 
	 * @param poorFamily
	 * @return
	 */
	@Override
	public PoorFamily getPoorFamily(PoorFamily poorFamily) {
		PoorFamily poorFamily0 = new PoorFamily();
		poorFamily0.setId(poorFamily.getId());
		poorFamily0.setProvince(poorFamily.getProvince());
		poorFamily0.setCity(poorFamily.getCity());
		poorFamily0.setCounty(poorFamily.getCounty());
		poorFamily0.setCountry(poorFamily.getCountry());
		poorFamily0.setVillage(poorFamily.getVillage());
		poorFamily0.setNumber(poorFamily.getNumber());
		poorFamily0.setContact(poorFamily.getContact());
		poorFamily0.setBank(poorFamily.getBank());
		poorFamily0.setCardNumber(poorFamily.getCardNumber());
		poorFamily0.setStandard(poorFamily.getStandard());
		poorFamily0.setPoverty(poorFamily.getPoverty());
		poorFamily0.setAttribute(poorFamily.getAttribute());
		poorFamily0.setSoldier(poorFamily.getSoldier());
		poorFamily0.setVehicle(poorFamily.getVehicle());
		poorFamily0.setRoom(poorFamily.getRoom());
		poorFamily0.setCompany(poorFamily.getCompany());
		poorFamily0.setReason(poorFamily.getReason());
		poorFamily0.setOther(poorFamily.getOther());
		poorFamily0.setCuedLand(poorFamily.getCuedLand());
		poorFamily0.setIrrigation(poorFamily.getIrrigation());
		poorFamily0.setWoodLand(poorFamily.getWoodLand());
		poorFamily0.setFarmLand(poorFamily.getFarmLand());
		poorFamily0.setFruit(poorFamily.getFruit());
		poorFamily0.setForageGrass(poorFamily.getForageGrass());
		poorFamily0.setWaters(poorFamily.getWaters());
		poorFamily0.setProduction(poorFamily.getProduction());
		poorFamily0.setCooperative(poorFamily.getCooperative());
		poorFamily0.setDistance(poorFamily.getDistance());
		poorFamily0.setType(poorFamily.getType());
		poorFamily0.setHousing(poorFamily.getHousing());
		poorFamily0.setLife(poorFamily.getLife());
		poorFamily0.setDifficulty(poorFamily.getDifficulty());
		poorFamily0.setSecurity(poorFamily.getSecurity());
		poorFamily0.setDanger(poorFamily.getDanger());
		poorFamily0.setLevel(poorFamily.getLevel());
		poorFamily0.setFuel(poorFamily.getFuel());
		poorFamily0.setToilet(poorFamily.getToilet());
		poorFamily0.setWages(poorFamily.getWages());
		poorFamily0.setOperating(poorFamily.getOperating());
		poorFamily0.setProperty(poorFamily.getProperty());
		poorFamily0.setTransfer(poorFamily.getTransfer());
		poorFamily0.setPlanning(poorFamily.getPlanning());
		poorFamily0.setLow(poorFamily.getLow());
		poorFamily0.setFive(poorFamily.getFive());
		poorFamily0.setPension(poorFamily.getPension());
		poorFamily0.setEcology(poorFamily.getEcology());
		poorFamily0.setElses(poorFamily.getElses());
		poorFamily0.setYear(poorFamily.getYear());
		poorFamily0.setExpenses(poorFamily.getExpenses());
		poorFamily0.setIncome(poorFamily.getIncome());
		poorFamily0.setPerCapita(poorFamily.getPerCapita());
		poorFamily0.setAlone(poorFamily.getAlone());
		poorFamily0.setTwoGirl(poorFamily.getTwoGirl());
		poorFamily0.setAddTime(poorFamily.getAddTime());
		poorFamily0.setUpTime(poorFamily.getUpTime());
		poorFamily0.setIsDel(poorFamily.getIsDel());
		poorFamily0.setFamily(poorFamily.getFamily());
		poorFamily0.setArea(poorFamily.getArea());
		poorFamily0.setHelpPersons(poorFamily.getHelpPersons());
		poorFamily0.setAreaCodes(poorFamily.getAreaCodes());
		return poorFamily0;
	}

	@Override
	public void removePoorFamily(Long id) {
		this.poorFaDao.deleteById(PoorFamily.class, id);

	}

	@Override
	public PoorFamily get(Long id) {
		return this.poorFaDao.get(id);
	}

	@Override
	public Pager<Map<String,Object>> getPFPager(int pageNo, int pageSize, PoorFamily poorFamily, String year, String name, String idNumber,
		String relation, McUser user) throws Exception {
		Map map = new HashMap<>();
		StringBuffer hql = new StringBuffer();
		
		String yearCondition  = StringUtils.isNotBlank(year) ? " and annual='"+year +"' " : "";
		
		// 贫困人口姓名
		String nameCondition = StringUtils.isNotBlank(name) ? " and name LIKE '%" + name + "%'" : "";
		// 证件号码
		String idNumberCondition = StringUtils.isNotBlank(idNumber) ? " and id_number LIKE '%" + idNumber + "%'" : "";
		// 与户主关系
		String relationCondition = StringUtils.isNotBlank(relation) ? " and relation LIKE '%" + relation + "%'" : "";
		

		// 省
		if (poorFamily.getProvince() != null && !"".equals(poorFamily.getProvince())) {
			String province = poorFamily.getProvince().replaceAll(" ", "");
			hql.append(" AND province like '%" + province + "%'");
		}
		// 市
		if (poorFamily.getCity() != null && !"".equals(poorFamily.getCity())) {
			String city = poorFamily.getCity().replaceAll(" ", "");
			hql.append(" AND city like '%" + city + "%'");
		}
		// 县
		if (poorFamily.getCounty() != null && !"".equals(poorFamily.getCounty())) {
			String county = poorFamily.getCounty().replaceAll(" ", "");
			hql.append(" AND county like '%" + county + "%'");
		}
		// 乡
		if (user.getUserLevel().getLevel() == 4) {
			if (poorFamily.getCountry() != null && !"".equals(poorFamily.getCountry())) {
				Area area = areaDao.getAreaByCode(poorFamily.getCountry());
				hql.append(" AND country like '%" + area.getArea() + "%'");
			} else {
				Area area = areaDao.getAreaByCode(user.getArea().getAreaCode());
				String cry = area.getArea();
				hql.append(" AND country like '%" + cry + "%'");
			}
		} else {
			if (poorFamily.getCountry() != null && !"".equals(poorFamily.getCountry())) {
				Area area = areaDao.getAreaByCode(poorFamily.getCountry());
				hql.append(" AND country like '%" + area.getArea() + "%'");
			}
		}

		// 村
		if (user.getUserLevel().getLevel() == 5) {
			if (poorFamily.getVillage() != null && !"".equals(poorFamily.getVillage())) {
				Area area = areaDao.getAreaByCode(poorFamily.getVillage());
				hql.append(" AND village like '%" + area.getArea() + "%'");
			} else {
				Area area = areaDao.getAreaByCode(user.getArea().getAreaCode());
				String villages = area.getArea();
				hql.append(" AND village like '%" + villages + "%'");
			}
		} else {
			if (poorFamily.getVillage() != null && !"".equals(poorFamily.getVillage())) {
				Area area = areaDao.getAreaByCode(poorFamily.getVillage());
				hql.append(" AND village like '%" + area.getArea() + "%'");
			}
		}

		// 贫困户属性
		if (poorFamily.getAttribute() != null && !"".equals(poorFamily.getAttribute())) {
			String attribute = poorFamily.getAttribute().replaceAll(" ", "");
			hql.append(" AND attribute like '%" + attribute + "%'");
		}
		// employment//就业途径：扶贫微工厂、大棚种植、搞养殖、家庭手工业、光伏、缝纫机、量资入股、其他
		if (StringUtils.isNotBlank(poorFamily.getEmployment())) {
			hql.append(" AND employment LIKE '%" + poorFamily.getEmployment() + "%' ");
		}
		// 脱贫状态
		if (poorFamily.getPoverty() != null && !"".equals(poorFamily.getPoverty())) {
			String poverty = poorFamily.getPoverty().replaceAll(" ", "");
			hql.append(" AND poverty like '%" + poverty + "%'");
		}
		
		hql.append(yearCondition);
		
		Pager page = null;
		if(StringUtils.isBlank(name) && StringUtils.isBlank(idNumber) && StringUtils.isBlank(relation)) {
			page =  poorFaDao.listPoorFamily("select *, (select count(*) from family where fid=p.id and annual=p.annual and is_del='0') as count from poorFamilyListView as p "
				+ "where 1=1 " + hql.toString(), 
				"select count(id) from poor_family force index(index_isDel_annual) where is_del='0' "  + hql.toString(), pageNo, pageSize);
		} else {
			page =  poorFaDao.listPoorFamily("select *, (select count(*) from family where fid=p.id and annual=p.annual and is_del='0') as count from (select fid from family where is_del=0 " 
				+ yearCondition + nameCondition + idNumberCondition + relationCondition +") as f,poorFamilyListView as p where f.fid=p.id " + hql.toString(), 
				"select count(id) from poor_family force index(index_isDel_annual) where is_del='0' "  + hql.toString(), pageNo, pageSize);
		}
		
		return page;
	}

	/**
	 * 结对查询获取贫困户列表
	 * @return
	 */
	@Override
	public Pager<PoorFamily> getPager(PoorFamily poorFamily, Integer pageNo, Integer pageSize, String name,
			String idNumber, String Whether,String year, McUser user) {
		Map map = new HashMap<>();
		StringBuffer hql = new StringBuffer();
		hql.append("FROM PoorFamily WHERE 1=1 and isDel= 0  and annual ='"+year+"'");
		// 省
		if (poorFamily.getProvince() != null && !"".equals(poorFamily.getProvince())) {
			String province = poorFamily.getProvince().replaceAll(" ", "");
			hql.append(" AND province like '%" + province + "%'");
		}
		// 市
		if (poorFamily.getCity() != null && !"".equals(poorFamily.getCity())) {
			String city = poorFamily.getCity().replaceAll(" ", "");
			hql.append(" AND city like '%" + city + "%'");
		}
		// 县
		if (poorFamily.getCounty() != null && !"".equals(poorFamily.getCounty())) {
			String county = poorFamily.getCounty().replaceAll(" ", "");
			hql.append(" AND county like '%" + county + "%'");
		}
		// 乡
		if (user.getUserLevel().getLevel() == 4) {
			if (poorFamily.getCountry() != null && !"".equals(poorFamily.getCountry())) {
				Area area = areaDao.getAreaByCode(poorFamily.getCountry());
				hql.append(" AND country like '%" + area.getArea() + "%'");
			} else {
				Area area = areaDao.getAreaByCode(user.getArea().getAreaCode());
				hql.append(" AND country like '%" + area.getArea() + "%'");
			}
		} else {
			if (poorFamily.getCountry() != null && !"".equals(poorFamily.getCountry())) {
				Area area = areaDao.getAreaByCode(poorFamily.getCountry());
				hql.append(" AND country like '%" + area.getArea() + "%'");
			}
		}
		// 村
		if (user.getUserLevel().getLevel() == 5) {
			if (poorFamily.getVillage() != null && !"".equals(poorFamily.getVillage())) {
				Area area = areaDao.getAreaByCode(poorFamily.getVillage());
				hql.append(" AND village like '%" + area.getArea() + "%'");
			} else {
				Area area = areaDao.getAreaByCode(user.getArea().getAreaCode());
				hql.append(" AND village like '%" + area.getArea() + "%'");
			}
		} else {
			if (poorFamily.getVillage() != null && !"".equals(poorFamily.getVillage())) {
				Area area = areaDao.getAreaByCode(poorFamily.getVillage());
				hql.append(" AND village like '%" + area.getArea() + "%'");
			}
		}
		// 贫困人口姓名
		if (name != null && !"".equals(name)) {
			String names = name.replaceAll(" ", "");
			hql.append(" AND id in (SELECT fid FROM Family WHERE name LIKE '%" + names + "%') ");
		}
		// 脱贫状态
		if (poorFamily.getPoverty() != null && !"".equals(poorFamily.getPoverty())) {
			String poverty = poorFamily.getPoverty().replaceAll(" ", "");
			hql.append(" AND poverty like '%" + poverty + "%'");
		}
		// 证件号码
		if (idNumber != null && !"".equals(idNumber)) {
			String idNumbers = idNumber.replaceAll(" ", "");
			hql.append(" AND id in (SELECT fid FROM Family WHERE idNumber LIKE '%" + idNumber + "%') ");
		}
		// 是否结对
		if ("0".equals(Whether)) {
			hql.append(" AND helpPersons.size = 0  ");
		}
		if ("1".equals(Whether)) {
			hql.append(" AND helpPersons.size > 0 ");
		}
		return this.poorFaDao.getPagerByHql(pageNo, pageSize, hql.toString(), map);
	}

	/**
	 * 贫困户模糊查询
	 */
	@Override
	public Pager<PoorFamily> getPHPager(int pageNo, int pageSize, PoorFamily poorFamily, String year, String name,
			String idNumber, String groupNumber, McUser user) {
		Map map = new HashMap<>();
		StringBuffer hql = new StringBuffer();
		hql.append("FROM PoorFamily WHERE isDel= '0'");
//		// 省
//		if (poorFamily.getProvince() != null && !"".equals(poorFamily.getProvince())) {
//			String province = poorFamily.getProvince().replaceAll(" ", "");
//			hql.append(" AND province like '%" + province + "%'");
//		}
//		// 市
//		if (poorFamily.getCity() != null && !"".equals(poorFamily.getCity())) {
//			String city = poorFamily.getCity().replaceAll(" ", "");
//			hql.append(" AND city like '%" + city + "%'");
//		}
//		// 县
//		if (poorFamily.getCounty() != null && !"".equals(poorFamily.getCounty())) {
//			String county = poorFamily.getCounty().replaceAll(" ", "");
//			hql.append(" AND county like '%" + county + "%'");
//		}
		
		if(!"未审核".equals(user.getCheckState())){
			//乡
			if (user.getUserLevel().getLevel() == 4) {
				if (poorFamily.getCountry() != null && !"".equals(poorFamily.getCountry())) {
					Area area = areaDao.getAreaByCode(poorFamily.getCountry());
					hql.append(" AND country like '" + area.getArea() + "'");
				} else {
					Area area = areaDao.getAreaByCode(user.getArea().getAreaCode());
					String cry = area.getArea();
					hql.append(" AND country like '" + cry + "'");
				}
			} else {
				if (poorFamily.getCountry() != null && !"".equals(poorFamily.getCountry())) {
					Area area = areaDao.getAreaByCode(poorFamily.getCountry());
					hql.append(" AND country like '" + area.getArea() + "'");
				}
			}
			
			// 村
			if (user.getUserLevel().getLevel() == 5) {
				if (poorFamily.getVillage() != null && !"".equals(poorFamily.getVillage())) {
					Area area = areaDao.getAreaByCode(poorFamily.getVillage());
					hql.append(" AND village like '" + area.getArea() + "'");
				} else {
					Area area = areaDao.getAreaByCode(user.getArea().getAreaCode());
					String villages = area.getArea();
					hql.append(" AND village like '" + villages + "'");
				}
			} else {
				if (poorFamily.getVillage() != null && !"".equals(poorFamily.getVillage())) {
					Area area = areaDao.getAreaByCode(poorFamily.getVillage());
					hql.append(" AND village like '" + area.getArea() + "'");
				}
			}
		}

		// 年度
		if (year != null && !"".equals(year)) {
			String years = year.replaceAll(" ", "");
			hql.append(" AND annual = '" + years + "'");
		}

		// 贫困户属性
		if (poorFamily.getAttribute() != null && !"".equals(poorFamily.getAttribute())) {
			String attribute = poorFamily.getAttribute().replaceAll(" ", "");
			hql.append(" AND attribute like '" + attribute + "'");
		}

		//防贫属性
        if(StringUtils.isNotBlank(poorFamily.getPreventAttribute())) {
		    hql.append( " AND PREVENT_ATTRIBUTE like '"+ poorFamily.getPreventAttribute().replaceAll(" ","") +"'");
        }

		// 脱贫状态
		if (poorFamily.getPoverty() != null && !"".equals(poorFamily.getPoverty())) {
			String poverty = poorFamily.getPoverty().replaceAll(" ", "");
            String[] ss = poverty.split(",");
            for(int i = 0;i<ss.length;i++) {
			    ss[i] = "'"+ ss[i] + "'";
            }
			hql.append(" AND poverty in("+ Arrays.toString(ss).replaceAll("[\\[\\]]", "")+")");
		}

		// 识别标准
		if (poorFamily.getStandard() != null && !"".equals(poorFamily.getStandard())) {
			String standard = poorFamily.getStandard().replaceAll(" ", "");
			hql.append(" AND standard like '" + standard + "'");
		}

		// 证件号码
		if (idNumber != null && !"".equals(idNumber)) {
			String idNumbers = idNumber.replaceAll(" ", "");
			hql.append(" AND id in (SELECT fid FROM Family WHERE  isDel='0' and idNumber LIKE '%" + idNumbers + "%') ");
		}

		// 姓名
		if (name != null && !"".equals(name)) {
			String names = name.replaceAll(" ", "");
			hql.append(" AND id in (SELECT fid FROM Family WHERE isDel='0' and  name LIKE '%" + names + "%') ");
		}

		// 组
		if (groupNumber != null && !"".equals(groupNumber)) {
			String groupNumbers = groupNumber.replaceAll(" ", "");
			hql.append(" AND area in (SELECT area FROM PoorVillage WHERE isDel='0' and groupNumber LIKE '" + groupNumbers + "')");
		}

		hql.append("ORDER BY poverty,number");
		// map.put("isDel", "0");
		Pager<PoorFamily> page = poorFaDao.getPagerByHql(pageNo, pageSize, hql.toString(), map);

		List<PoorFamily> result = new ArrayList<>();
		List<Family> families = null;
		for(PoorFamily pf : page.getResultList()) {
			PoorFamily tempPF = new PoorFamily();
			families = new ArrayList<>();
			for(Family f : pf.getFamily()) {
			    if("0".equals(f.getIsDel())) {families.add(f);}
			}
            BeanUtils.copyProperties(pf,tempPF);
			tempPF.setFamily(families);
			result.add(tempPF);
		}

		page.setResultList(result);
		return page;
	}

	/**
	 * 贫困村个数
	 */
	@Override
//	@Cacheable(value="indexStatistics",key="'totalFamily'")
	public List totalPoor() {
		String annual = ApplicationProperties.getAnnual();
//		Element element = manager.getCache("indexStatistics").get("totalFamily");
//		if(element != null) {
//			return (List) element.getObjectValue();
//		}
		List laborTypeCount = new ArrayList<>();
		Map<String, Object> typeVerbose = null;
		List list = new ArrayList<>();
		laborTypeCount = poorFaDao
				.find("SELECT new map( country as region , COUNT(attribute) as totalPV) FROM PoorFamily WHERE isDel = '0' and poverty!='已脱贫（不再享受政策）' and poverty!='防贫户'and annual = '"
						+ annual + "' GROUP BY country");

		log.info("当前查询年度"+annual);
		for (Object o : laborTypeCount) {
			typeVerbose = new HashMap<>();
			typeVerbose.put("name", ((Map) o).get("region")); // 地区
			typeVerbose.put("value", ((Map) o).get("totalPV"));// 总贫困村数
			list.add(typeVerbose);
		}
		
		manager.getCache("indexStatistics").put(new Element("totalFamily", list));
		return list;
	}

	/**
	 * 户主查询
	 * 
	 * @return
	 */
	@Override
	public List<Family> findHouseholder(Integer... ids) {
		return poorFaDao.findHouseholder(ids);
	}

	/**
	 * 证件号重复查询
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @param year
	 * @param country
	 */
	@Override
	@SuppressWarnings("all")
	public Pager<?> complexQueryDuplicateID(Integer pageNo, Integer pageSize, String year, String country, McUser user) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 12 : pageSize;
		// 级别错误
		if (user.getUserLevel().getLevel() < 0 || user.getUserLevel().getLevel() > 5) {
			return new Pager(pageSize, pageNo, 0, new ArrayList<>());
		}

		return poorFaDao.queryDuplicateID(pageNo, pageSize, year, country, user);
	}

	/**
	 * 导入贫困户
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public String adduploadFile(String file, HttpSession session, McUser mcUser) throws Exception {
		// 获取本地exc全路径
		String classPath = this.getClass().getClassLoader().getResource("").getPath();
		String excelFile = classPath.substring(1, classPath.indexOf("/WEB-INF")) + file;
		File files = new File(excelFile);
		if (!files.exists()) {
			return "NO_URL";
		}
		// 解析Excel文件
		Map data = new HashMap();
		// 地区数据：
		Map<String, Long> areaMap = gainAreaMap();
		try {
			data = PoorFamilyControllerExcelHandler.readExcel(excelFile,areaMap);
			if (StringUtil.isNotBlank((String) data.get("errInfo"))) {
				return data.get("errInfo").toString();
			}
			data.remove("errInfo");
			data.remove("rows");
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			//最后删除上传文件
			files.delete();
		}
		////////// 数据sta
		// 比较数据准备：数据
		long dataTimeS = System.currentTimeMillis();
	
		// 贫困户 家庭成员数据：
		Map<String, Object> poorFMap = gainPoorfMap();
		
		// 贫困户数据：
		 Map<String, Long> poorFMapId = gainPoorfMaps();
		
		// 家庭成员数据：
		/*Map<String, Object> famMap = gainFamMap();*/
		
		long dataTimeE = System.currentTimeMillis();
		////////// 数据end
		System.out.println(dataTimeE - dataTimeS + "S>>>>>>贫困户获取比较的数据耗时");
		log.info(dataTimeE - dataTimeS + "S>>>>>>贫困户获取比较的数据耗时");

		// 储存已插入的贫困户  家庭成员
		Map<String, Object> poorFMaps = new HashMap<String, Object>();
		// 储存已插入的贫困户
		Map<String, Long> poorFMapsId = new HashMap<String, Long>();
		// 储存已删除的应家庭成员贫困户ID
		List<Long> delPfIdList = new ArrayList();
		// 储存需要添加的家庭成员
		List<Map<String, Object>> addfamilyList = new ArrayList<Map<String, Object>>();
		// 储存需要更新的家庭成员
		List<Map<String, Object>> upfamilyList = new ArrayList<Map<String, Object>>();
		// 储存需要更新的贫困户
		List<Map<String, Object>> upPfList = new ArrayList<Map<String, Object>>();

		// 影响到的贫困村
        HashSet<String> affectedPoorVillage = new HashSet<>();
		// 依次将data中的数据映射到Signind对象并保存到数据库
		Set<Object> keySet = data.keySet();
		for (Object obj : keySet) {
			ArrayList<PoorFamilyExcelVo> poorFamilyList = new ArrayList<PoorFamilyExcelVo>();
			poorFamilyList = (ArrayList<PoorFamilyExcelVo>) data.get(obj);
			for (PoorFamilyExcelVo poorfExc : poorFamilyList) {
				try {// 处理特殊的字段
					
					//家庭成员id
					 fid = null;
						// 贫困户逻辑处理
					PoorFamily poorFamily = addOrUpdatePoorFamily(poorfExc, areaMap, poorFMap, poorFMaps, delPfIdList,
							upPfList,fid,poorFMapId,poorFMapsId);
                    if(poorFamily.getArea().getId() != null ) {
                        affectedPoorVillage.add(poorFamily.getArea().getId().toString());
                    }
					// 家庭逻辑处理
					addOrUpdateFamily(poorfExc, poorFamily, addfamilyList,upfamilyList,fid);
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		}

		// 删除家庭成员
	/*	if (delPfIdList != null && delPfIdList.size() > 0) {
			familyDao.delFamilyPfId(delPfIdList);
		}*/
		String sql = null;
		// 添加家庭成员  
		if (addfamilyList != null && addfamilyList.size() > 0) {
			sql = "insert into family(Number,Name,ID_NUMBER,Relation,Nation,Culture,School,Healthy,Labour,Province,Work_Time,Large,Is_Del,Annual,Fid,Add_Time,State,city,county,village) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			Install.executeBatch(sql, 20, addfamilyList);
		}
		
		// 更新家庭成员  
		if (upfamilyList != null && upfamilyList.size() > 0) {
			sql = "update family set Number=?,Name=?,ID_NUMBER=?,Relation=?,Nation=?,Culture=?,School=?,Healthy=?,Labour=?,Province=?,Work_Time=?,Large=?,Is_Del=?,Annual=?,Fid=?,Add_Time=?,State=?,city=?,county=?,village=? where id=?";
			Install.executeBatch(sql, 21, upfamilyList);
		}
		
		// 更新贫困户
		if (upPfList != null && upPfList.size() > 0) {
			sql = "update poor_family set UP_TIME=?,county=?,country=?,village=?,name=?,number=?,poverty=?,attribute=?,reason=?,danger=?,security=?,difficulty=?,perCapita=?,security=?,contact=?,AREA_ID=? where id=? ";
			Install.executeBatch(sql, 17, upPfList);
		}

		//更新受影响的贫困村记录中的贫困户数和贫困人口数
        String annual = ApplicationProperties.getAnnual();
        for(String areaID : affectedPoorVillage) {
		    tableMaintenance.updatePoorFamilyCount(annual,Long.parseLong(areaID));
		    tableMaintenance.updateFamilyCount(annual,Long.parseLong(areaID));
        }

		// 清空数据
		areaMap.clear();
		poorFMap.clear();
		poorFMapId.clear();
		poorFMaps.clear();
		poorFMapsId.clear();
		upPfList.clear();
		addfamilyList.clear();
		upfamilyList.clear();
		return "T";

	}

	/**
	 * 获取所有家庭成员数据遍历到Map
	 * 
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map<String, Object> gainFamMap() {
		Map<String, Object> famMap = new HashMap<String, Object>();
/*		Map mapC = new HashMap<>();
		mapC.put("annual", ApplicationProperties.getAnnual());
		List<Object[]> Familys = this.poorFaDao.queryList("select p.number,f.idNumber,f.id,p.id from Family f,PoorFamily p where f.fid=p.id and p.isDel='0' and  annual=:annual ", mapC);
		for (Object[] p : Familys) {
			famMap.put((String) p[0], (String) p[1]+"_"+(String) p[2]+"_"+(Long) p[3]);
		}*/
		return famMap;
	}

	/**
	 * 获取所有贫困户数据遍历到Map
	 * 
	 * @return
	 */
/*	@SuppressWarnings({ "unchecked", "rawtypes", "unused" })
	public Map<String, Long> gainPoorfMap() {
		Map<String, Long> poorFMap = new HashMap<String, Long>();
		Map map = new HashMap<>();
		map.put("annual", ApplicationProperties.getAnnual());
		List<Object[]> poorFamilys = this.poorFaDao
				.queryList(" select p.number ,p.id from PoorFamily p where isDel='0' and annual=:annual ", map);
		for (Object[] p : poorFamilys) {
			poorFMap.put((String) p[0], (Long) p[1]);

		}
		return poorFMap;
	}*/
	
	@SuppressWarnings({ "unchecked", "rawtypes", "unused" })
	public Map<String, Long> gainPoorfMaps() {
		Map<String, Long> poorFMap = new HashMap<String, Long>();
		Map map = new HashMap<>();
		map.put("annual", ApplicationProperties.getAnnual());
		List<Object[]> poorFamilys = this.poorFaDao
				.queryList(" select p.number ,p.id from PoorFamily p where isDel='0' and annual=:annual ", map);
		for (Object[] p : poorFamilys) {
			poorFMap.put((String) p[0], (Long) p[1]);

		}
		return poorFMap;
	}
	
	
	@SuppressWarnings({ "unchecked", "rawtypes", "unused" })
	public Map<String, Object> gainPoorfMap() {
		Map<String, Object> poorFMap = new HashMap<String, Object>();
		Map map = new HashMap<>();
		map.put("annual", ApplicationProperties.getAnnual());
	/*	List<Object[]> poorFamilys = this.poorFaDao
				.queryList(" select p.number ,p.id from PoorFamily p where isDel='0' and annual=:annual ", map);
		for (Object[] p : poorFamilys) {
			poorFMap.put((String) p[0], (Long) p[1]);

		}*/
		List<Object[]> poorFamilys = this.poorFaDao.queryList("select p.number, f.idNumber,f.id,p.id from Family f,PoorFamily p where f.fid=p.id and p.isDel='0' and   p.annual=:annual and f.annual=:annual ", map);
		for (Object[] p : poorFamilys) {
			poorFMap.put(p[0].toString()+"_"+p[1].toString(), p[1].toString()+"_"+p[2].toString()+"_"+p[3].toString());
		}
		
		return poorFMap;
	}
	

	/**
	 * 获取所有地区数据遍历到Map
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Long> gainAreaMap() {
		Map<String, Long> areaMap = new HashMap<String, Long>(1024);
//		List<Area> areas = this.poorFaDao.queryList(" from Area a ", new HashMap<>(0));
		List<Object[]> areas = this.poorFaDao.queryList("SELECT a.area,a1.area,a1.id FROM Area a  ,Area a1 WHERE a.id=a1.fatherId ", new HashMap<>(0));
		for (Object[] as : areas) {
			//乡镇_村，
			areaMap.put(as[0]+"_"+as[1], (Long) as[2]);
		}
		return areaMap;
	}

	/**
	 * exc导入 添加或者更新 PoorFamily
	 * 
	 * @param poorfExc
	 * @param poorFMap
	 * @param areaMap
	 * @param poorFMaps
	 * @param delPfIdList
	 * @param upPfList
	 * @param isBackup 
	 * @param fid 
	 * @param poorFMapId 
	 * @param poorFMapsId 
	 * @return
	 */

	@SuppressWarnings("unchecked")
	public PoorFamily addOrUpdatePoorFamily(PoorFamilyExcelVo poorfExc, Map<String, Long> areaMap,
			Map<String, Object> poorFMap, Map<String, Object> poorFMaps, List<Long> delPfIdList,
			List<Map<String, Object>> upPfList, Long fid, Map<String, Long> poorFMapId, Map<String, Long> poorFMapsId) {
		// 贫困户ID
		String idNumber_fid_pid = null;
		Long pid = null;
		
		
		// 贫困户表
		PoorFamily poorFamily = new PoorFamily();
		// 在新插入的poorFMaps贫困户里面找是否有该数据
		if(poorFMapsId.containsKey(poorfExc.getNumberH())){
		     pid = Long.valueOf(poorFMapsId.get(poorfExc.getNumberH()));
			//家庭成员判断
			if(poorFMaps.containsKey(poorfExc.getNumberH()+"_"+poorfExc.getIdNumber())){
				 idNumber_fid_pid = (String) poorFMaps.get(poorfExc.getNumberH()+"_"+poorfExc.getIdNumber());
				 pid = Long.valueOf(idNumber_fid_pid.split("_")[2]);
				 fid =  Long.valueOf(idNumber_fid_pid.split("_")[1]);
			}
			 poorFamily.setId(pid);
			 
		}// 在数据库查找贫困户是否有该数据 //贫困户判断
		 if(poorFMapId.containsKey(poorfExc.getNumberH())){
		     pid = Long.valueOf(poorFMapId.get(poorfExc.getNumberH()));
			//家庭成员判断
			if(poorFMap.containsKey(poorfExc.getNumberH()+"_"+poorfExc.getIdNumber())){
				 idNumber_fid_pid = (String) poorFMap.get(poorfExc.getNumberH()+"_"+poorfExc.getIdNumber());
				 pid = Long.valueOf(idNumber_fid_pid.split("_")[2]);
				 fid =  Long.valueOf(idNumber_fid_pid.split("_")[1]);
			}
			 poorFamily.setId(pid);
			 
		}
		poorFamily.setName(poorfExc.getNameH());// 自然村字段:（新增字段）
		poorFamily.setCounty(poorfExc.getCounty());// 县(市、区、旗)
		poorFamily.setCountry(poorfExc.getCountry());// 乡（镇）
		poorFamily.setVillage(poorfExc.getVillage());// 行政村
		poorFamily.setNumber(poorfExc.getNumberH());// 户编号
		poorFamily.setPoverty(poorfExc.getPoverty());// 脱贫属性
		poorFamily.setAttribute(poorfExc.getAttribute());// 贫困户属性
		poorFamily.setReason(poorfExc.getReason());// 主要致贫原因
		poorFamily.setDanger(poorfExc.getDanger());// 危房户
		poorFamily.setSecurity(poorfExc.getSecurity());// 饮水安全
		poorFamily.setDifficulty(poorfExc.getDifficulty());// 饮水是否困难
		poorFamily.setPerCapita(poorfExc.getPerCapita());// 人均纯收入
		poorFamily.setContact(poorfExc.getContact());// 联系电话
		// 判断地区是否存在
		Area a = new Area();
		a.setId(areaMap.get(poorfExc.getCountry()+"_"+poorfExc.getVillage()));
		poorFamily.setArea(a);
		poorFamily.setProvince("河北省");
		poorFamily.setCity("邯郸市");
		int year = Calendar.getInstance().get(Calendar.YEAR);
		poorFamily.setAnnual(ApplicationProperties.getAnnual());// 业务年度
		poorFamily.setIsDel("0");
		// 判断贫困户是否存在
		if (pid != null) {
			poorFamily.setUpTime(new Date());
			// poorFaDao.update(poorFamily);
			/////////////////// STA（获取Batch数据）
			
		   if(poorFMapsId.get(poorFamily.getNumber()) != pid ){
				Map<String, Object> addPfMap = poorFamilyBatchPara(poorFamily, 0);
				upPfList.add(addPfMap);
		   }
			
			/////////////////// EMD
		 
			
		/*	// 如果是更新的话，需要覆盖该贫困户下所有的家庭成员信息，也就是说需要把之前的家庭成员信息删除，然后以最新导入的显示
			if (!delPfIdList.contains(poorFamily.getId())) {
				delPfIdList.add(poorFamily.getId());
			}*/
			// 储存已插入或更新贫困户的信息 idNumber_fid_pid
			poorFMaps.put(poorFamily.getNumber()+"_"+poorfExc.getIdNumber(), poorfExc.getIdNumber()+"_"+fid+"_"+pid);
			
			poorFMapsId.put(poorFamily.getNumber(), poorFamily.getId());
			
			this.fid= fid;

		} else if (pid == null) {
			poorFamily.setAddTime(new Date());
			poorFaDao.importPoorFamily(poorFamily);
			// 储存已插入或更新贫困户的信息
		    poorFMaps.put(poorFamily.getNumber()+"_"+poorfExc.getIdNumber(), poorfExc.getIdNumber()+"_"+fid+"_"+pid);
			poorFMapsId.put(poorFamily.getNumber(), poorFamily.getId());
			this.fid= fid;
		}
		return poorFamily;
	}

	/**
	 * 获取Batch数据
	 * 
	 * @param poorFamily
	 * @param type
	 *            0添加 1更新 2删除
	 * @return
	 */
	private Map<String, Object> poorFamilyBatchPara(PoorFamily poorFamily, Integer type) {
		Map<String, Object> addPfMap = new HashMap<String, Object>();
		addPfMap.put("1", poorFamily.getUpTime());
		addPfMap.put("2", poorFamily.getCounty());
		addPfMap.put("3", poorFamily.getCountry());
		addPfMap.put("4", poorFamily.getVillage());
		addPfMap.put("5", poorFamily.getName());
		addPfMap.put("6", poorFamily.getNumber());
		addPfMap.put("7", poorFamily.getPoverty());
		addPfMap.put("8", poorFamily.getAttribute());
		addPfMap.put("9", poorFamily.getReason());
		addPfMap.put("10", poorFamily.getDanger());
		addPfMap.put("11", poorFamily.getSecurity());
		addPfMap.put("12", poorFamily.getDifficulty());
		addPfMap.put("13", poorFamily.getPerCapita());
		addPfMap.put("14", poorFamily.getSecurity());
		addPfMap.put("15", poorFamily.getContact());
		addPfMap.put("16", poorFamily.getArea() != null ? poorFamily.getArea().getId() : null);
		addPfMap.put("17", poorFamily.getId());
		return addPfMap;
	}
	/**
	 * exc导入 储存添加或者更新 Family
	 * 
	 * @param poorfExc
	 * @param poorFamily
	 * @param addfamilyList
	 * @param upfamilyList 
	 * @param isBackup 
	 * @param fid 
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> addOrUpdateFamily(PoorFamilyExcelVo poorfExc, PoorFamily poorFamily,
			List<Map<String, Object>> addfamilyList, List<Map<String, Object>> upfamilyList, Long fid) {
		Family family = new Family();
		if(fid!=null){
			family.setId(fid);
		}
		
		// 查找贫困户是否有该数据：根据户编号和身份证号查询,存在更新否则添加
		// 贫困户表
		family.setNumber(poorfExc.getNumberP());// 人编号
		family.setName(poorfExc.getName());// 姓名
		family.setIdNumber(poorfExc.getIdNumber());// 证件号码
		// family.setPeNumber(poorfExc.peNumber());//人数 //未找到该字段
		family.setRelation(poorfExc.getRelation());// 与户主关系
		family.setNation(poorfExc.getNation());// 民族
		family.setCulture(poorfExc.getCulture());// 文化程度
		family.setSchool(poorfExc.getSchool());// 在校生状况
		family.setHealthy(poorfExc.getHealthy());// 健康状况
		family.setLabour(poorfExc.getLabour());// 劳动技能

//		family.setProvince(poorfExc.getProvince());// 上年务工所在省(务工状况 )
        //务工状况处理
        family.setProvince("");
        family.setCity("");
        family.setCounty("");
        family.setVillage("");
        String laborCase = poorfExc.getProvince();
        laborCase = StringUtils.isBlank(laborCase) ? "" : laborCase;
        if(laborCase.contains("乡镇内")) {
            family.setProvince("河北省");
            family.setCity("邯郸市");
            family.setCounty("魏县");
            family.setVillage(poorfExc.getCountry());

        } else if(laborCase.contains("县内")) {
            family.setProvince("河北省");
            family.setCity("邯郸市");
            family.setCounty("魏县");

        } else if(laborCase.contains("市内")) {
            family.setProvince("河北省");
            family.setCity("邯郸市");

        } else if(laborCase.contains("省内")) {
            family.setProvince("河北省");
        }

		family.setWorkTime(poorfExc.getWorkTime());// 务工时间（月）(上年务工时间)
		family.setLarge(poorfExc.getLarge());// 参加大病医疗
		family.setIsDel("0");
		int year = Calendar.getInstance().get(Calendar.YEAR);
		family.setAnnual(ApplicationProperties.getAnnual());// 业务年度
		family.setFid(poorFamily.getId());
		// 判断家庭成员是否存在
		family.setAddTime(new Date());
		family.setState("1");// 状态0为新增 1为修改
		// poorFaDao.save(family);
		//////////// STA（获取Batch数据）
		if(fid==null){
		Map<String, Object> addFamilyMap = FamilyBatchPara(family, 0);
		addfamilyList.add(addFamilyMap);
		}else{
			Map<String, Object> addFamilyMap = FamilyBatchPara(family, 1);
			upfamilyList.add(addFamilyMap);
			
		}
		/////////// EMD
		// familyList.add(family);
		return addfamilyList;

	}

	/**
	 * 获取Batch数据
	 * 
	 * @param family
	 * @param type
	 * @return
	 */
	private Map<String, Object> FamilyBatchPara(Family family, Integer type) {
		Map<String, Object> addFamilyMap = new HashMap<String, Object>();
		addFamilyMap.put("1", family.getNumber());
		addFamilyMap.put("2", family.getName());
		addFamilyMap.put("3", family.getIdNumber());
		addFamilyMap.put("4", family.getRelation());
		addFamilyMap.put("5", family.getNation());
		addFamilyMap.put("6", family.getCulture());
		addFamilyMap.put("7", family.getSchool());
		addFamilyMap.put("8", family.getHealthy());
		addFamilyMap.put("9", family.getLabour());
		addFamilyMap.put("10", family.getProvince());
		addFamilyMap.put("11", family.getWorkTime());
		addFamilyMap.put("12", family.getLarge());
		addFamilyMap.put("13", family.getIsDel());
		addFamilyMap.put("14", family.getAnnual());
		addFamilyMap.put("15", family.getFid());
		addFamilyMap.put("16", family.getAddTime());
		addFamilyMap.put("17", family.getState());
		addFamilyMap.put("18",family.getCity());
		addFamilyMap.put("19",family.getCounty());
		addFamilyMap.put("20",family.getVillage());

		if(1==type){
			addFamilyMap.put("21", family.getId());
		}
		
		return addFamilyMap;
	}

	@Override
	public List<PoorFamily> findCurrentPoorFamilyByCountry(String country) {
		String hql = "from  PoorFamily where YEAR(addTime)=YEAR(now()) and  country='" + country + "'";
		return poorFaDao.find(hql);
	}

	@Override
	public List<PoorFamily> findPoorFamilyByReason(String reason) {
		String hql = "from PoorFamily where reason='" + reason.trim() + "'";
		return poorFaDao.find(hql);
	}

	/**
	 * 重复证件号记录导出
	 */
	@Override
	public HSSFWorkbook complexExportDuplicateIDExcel(Integer pageNo, Integer pageSize, String year, String country,
			McUser user) {

		String[] cellName = new String[] { "序号", "证件号码", "姓名", "与户主关系", "户主", "省", "市", "县", "镇", "行政府", "组", "脱贫属性",
				"贫困户属性" };
		String[] field = new String[] { "idNumber", "name", "relation", "householder", "province", "city", "county",
				"country", "area", "groupNumber", "poverty", "attribute" };

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = complexQueryDuplicateID(sheetCount, 5000, year, country, user);
			excelResult.put(sheetCount, pager.getResultList());

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		HSSFWorkbook workbook = new HSSFWorkbook();

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("证件号重复记录表" + i);
			sheet.setDefaultColumnWidth(13);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "证件号重复记录表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, excelResult.get(i), field, cellStyle, true);
		}

		return workbook;
	}

	/**
	 * 户主异常查询
	 */
	@Override
	@SuppressWarnings("all")
	public Pager complexQueryExceptHouseholder(String year, String country, String village, Integer type, Integer pageNo,
			Integer pageSize, McUser user) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 12 : pageSize;
		// 级别错误
		if (user.getUserLevel().getLevel() < 0 || user.getUserLevel().getLevel() > 5) {
			return new Pager(pageSize, pageNo, 0, new ArrayList<>());
		}

		return poorFaDao.queryExceptHouseholder(year, country, village, type, pageNo, pageSize, user);
	}

	/**
	 * 户主异常excel导出
	 */
	@Override
	public HSSFWorkbook complexExportExceptHouseholder(String year, String country, String village, Integer type,
			McUser user) {

		String[] cellName = new String[] { "序号", "户编号", "人编号", "姓名", "性别", "证件号码", "与户主关系", "民族", "人数", "是否搬迁户",
				"异常情况" };
		String[] field = new String[] { "familyNo", "personNo", "name", "sex", "idNumber", "relation", "nation",
				"count", "migrate", "exceptType" };

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = complexQueryExceptHouseholder(year, country, village, type, sheetCount, 5000, user);
			excelResult.put(sheetCount, pager.getResultList());

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		HSSFWorkbook workbook = new HSSFWorkbook();

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("户主异常记录表" + i);
			sheet.setDefaultColumnWidth(13);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "户主异常记录表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, excelResult.get(i), field, cellStyle, true);
		}

		return workbook;
	}

	/**
	 * 贫困户学生查询
	 */
	@Override
	@SuppressWarnings("all")
	public Pager complexQueryPoorStudent(String year, String country, Family family, Integer pageNo, Integer pageSize,
			McUser user) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 12 : pageSize;
		// 级别错误
		if (user.getUserLevel().getLevel() < 0 || user.getUserLevel().getLevel() > 5) {
			return new Pager(pageSize, pageNo, 0, new ArrayList<>());
		}

		return poorFaDao.queryPoorStudent(year, country, family, pageNo, pageSize, user);
	}

	/**
	 * 贫困户学生导出
	 */
	@Override
	public HSSFWorkbook complexExportPoorStudent(String year, String country, Family family, McUser user) {
		String[] cellName = new String[] { "序号", "县", "乡镇", "村", "户主姓名", "户主证件号", "学生姓名", "学生证件号", "院校名称", "入学时间", "专业",
				"学制", "是否在校", "办学类型" };
		String[] field = new String[] { "county", "country", "village", "householder", "householderIdNumber", "name",
				"idNumber", "schoolName", "enterTime", "major", "institution", "isStudent", "doType" };

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = complexQueryPoorStudent(year, country, family, sheetCount, 5000, user);
			excelResult.put(sheetCount, pager.getResultList());

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		HSSFWorkbook workbook = new HSSFWorkbook();

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("贫困户学生记录表" + i);
			sheet.setDefaultColumnWidth(13);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "贫困户学生记录表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, excelResult.get(i), field, cellStyle, true);
		}
		return workbook;
	}

	/**
	 * 贫困户管理导出
	 * @throws Exception 
	 */
	@Override
	public HSSFWorkbook exportPoorFamily(PoorFamily poorFamily, String year, String name, String idNumber, String relation,McUser user) throws Exception {

		String[] cellName = new String[] { "序号", "所在乡","所在村","户编号", "户主个人编号", "户主姓名", "户主证件号码", "脱贫状态", "家庭人口数", "贫困户属性","人均纯收入","防贫属性","防贫原因" };

		String[] field = new String[] { "cry","village","pNumber", "hNumber", "hName", "hIdNumber", "poverty", "count", "attribute","perCapita","preventAttribute","preventReason"};

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();
		//String  = name;
		do {
		    List<Map<String,String>> list = new ArrayList<>();
			sheetCount++;
			pager = getPHPager(sheetCount, 5000,poorFamily, year, name, idNumber, relation,user);

			for(PoorFamily p : (List<PoorFamily>)pager.getResultList()) {
			    int count = 0;
			    Family houseHolder = new Family();
			    for( Family f : p.getFamily()) {
			        if("0".equals(f.getIsDel())) {
			            count ++;
			            if("户主".equals(f.getRelation())) {
                            houseHolder = f;
                        }
                    }
                }
                Map<String, String> map = Collections.generateHashMap(
                        "cry", p.getCountry(),
                        "village", p.getVillage(),
                        "pNumber", p.getNumber(),
                        "hNumber", houseHolder.getNumber(),
                        "hName", houseHolder.getName(),
                        "hIdNumber", houseHolder.getIdNumber(),
                        "poverty", p.getPoverty(),
                        "count", count,
                        "attribute", p.getAttribute(),
                        "perCapita",p.getPerCapita(),
                        "preventAttribute", p.getPreventAttribute(),
                        "preventReason", p.getPreventReason()
                );
                list.add(map);
            }
			excelResult.put(sheetCount,list);

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		HSSFWorkbook workbook = new HSSFWorkbook();

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("贫困户记录表" + i);
			sheet.setDefaultColumnWidth(20);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "贫困户记录表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, excelResult.get(i), field, cellStyle, true);
		}
		return workbook;
	}

	/**
	 * 贫困户查询导出
	 */
	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportPoorFamilyZ(String year, PoorFamily poorFamily, McUser user, String name, String idNumber,
			String groupNumber) {

		String[] cellName = new String[] { "序号", "乡（镇）", "村", "户编号", "人编号", "姓名", "性别", "证件号码", "人数", "与户主关系", "民族",
				"文化程度", "在校生状况", "健康情况", "劳动技能", "务工状况", "务工时间（月）", "脱贫状态", "贫困户属性", "主要致贫原因", "联系电话", "开户银行名称",
				"银行卡号" };

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = getPHPager(sheetCount, 50000, poorFamily, year, name, idNumber, groupNumber, user);
			excelResult.put(sheetCount, pager.getResultList());

		} while (sheetCount < (pager.getRowCount() + 49999) / 50000);

		List fList = new ArrayList<>();
		for (Object e : pager.getResultList()) {
			List<Family> family = ((PoorFamily) e).getFamily();
			Map map = new LinkedHashMap<>();
			map.put("number", ((PoorFamily) e).getNumber());
			map.put("poverty", ((PoorFamily) e).getPoverty());
			map.put("attribute", ((PoorFamily) e).getAttribute());
			map.put("reason", ((PoorFamily) e).getReason());
			map.put("contact", ((PoorFamily) e).getContact());
			map.put("bank", ((PoorFamily) e).getBank());
			map.put("cardNumber", ((PoorFamily) e).getCardNumber());
			map.put("country", ((PoorFamily) e).getCountry());
			map.put("village", ((PoorFamily) e).getVillage());
			map.put("flength", family.size());
			if (((PoorFamily) e).getFamily().size() > 0) {
				map.put("fnumber", ((PoorFamily) e).getFamily().get(0).getNumber());
				map.put("fname", ((PoorFamily) e).getFamily().get(0).getName());
				map.put("fsex", ((PoorFamily) e).getFamily().get(0).getSex());
				map.put("fidNumber", ((PoorFamily) e).getFamily().get(0).getIdNumber());
				map.put("fworkTime", ((PoorFamily) e).getFamily().get(0).getWorkTime());
				map.put("frelation", ((PoorFamily) e).getFamily().get(0).getRelation());
				map.put("fnation", ((PoorFamily) e).getFamily().get(0).getNation());
				map.put("fculture", ((PoorFamily) e).getFamily().get(0).getCulture());
				map.put("fschool", ((PoorFamily) e).getFamily().get(0).getSchool());
				map.put("fhealthy", ((PoorFamily) e).getFamily().get(0).getHealthy());
				map.put("flabour", ((PoorFamily) e).getFamily().get(0).getLabour());
				map.put("fprovince", ((PoorFamily) e).getFamily().get(0).getProvince());
			}
			// for (Family family2 : family) {
			// Map map_2 = new LinkedHashMap<>();
			// map_2.put("fnumber", family2.getNumber());
			// map_2.put("fname", family2.getName());
			// map_2.put("fsex", family2.getSex());
			// map_2.put("fidNumber", family2.getIdNumber());
			// map_2.put("fworkTime", family2.getWorkTime());
			// map_2.put("frelation", family2.getRelation());
			// map_2.put("fnation", family2.getNation());
			// map_2.put("fculture", family2.getCulture());
			// map_2.put("fschool", family2.getSchool());
			// map_2.put("fhealthy", family2.getHealthy());
			// map_2.put("flabour", family2.getLabour());
			// map_2.put("fprovince", family2.getProvince());
			// fList.add(map_2);
			// }
			fList.add(map);
		}

		HSSFWorkbook workbook = new HSSFWorkbook();

		String[] field = new String[] { "country", "village", "number", "fnumber", "fname", "fsex", "fidNumber",
				"flength", "frelation", "fnation", "fculture", "fschool", "fhealthy", "flabour", "fprovince",
				"fworkTime", "poverty", "attribute", "reason", "contact", "bank", "cardNumber" };

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("贫困户记录表" + i);
			sheet.setDefaultColumnWidth(13);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "贫困户记录表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, fList, field, cellStyle, true);
		}
		return workbook;
	}

	@Override
	public List complexQueryIncomeInfo() {
//		Element element = manager.getCache("indexStatistics").get("income");
//		if(element != null) {
//			return (List) element.getObjectValue();
//		}
		List queryIncomeInfo = poorFaDao.queryIncomeInfo();
		manager.getCache("indexStatistics").put(new Element("income", queryIncomeInfo));
		return queryIncomeInfo;
	}

	@Override
	public List queryMainPovertyCauses( ) {
//		Element element = manager.getCache("indexStatistics").get("poorCauseStat");
//		if(element != null) {
//			return (List) element.getObjectValue();
//		}
		List result = poorFaDao.queryMainPovertyCauses();
		manager.getCache("indexStatistics").put(new Element("poorCauseStat", result));
		return result;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Pager queryPoorPeople(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		// 参数的初始化
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryPoorPeople(user, pageNo, pageSize, year, town, poverty);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportPoorPeople(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困人口", "女性人数", "女性占比", "少数民族人数", "少数民族占比", "残疾人数", "残疾占比",
				"现役军人人数", "现役军人占比", "享受低保人数", "享受低保占比", "参加大病保险人数", "参加大病保险占比" };
		String[] field = new String[] { "area", "totalPoorPeople", "womanCount", "womanRatio", "nationCount",
				"nationRatio", "disabilityCount", "disabilityCountRatio", "serviceCount", "serviceCountRatio",
				"lowCount", "lowCountRatio", "largeCount", "largeCountRatio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryPoorPeople(user, null, null, year,
				town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困人口基本信息统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困人口基本信息统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryAgeGroup(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		// 参数的初始化
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryAgeGroup(user, pageNo, pageSize, year, town, poverty);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportAgeGroup(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困人口", "平均年龄", "16岁以下人数", "16岁以下比例", "16岁-30岁人数", "16岁-30岁比例",
				"30岁-40岁人数", "30岁-40岁比例", "40岁-50岁人数", "40岁-50岁比例", "50岁-60岁人数", "50岁-60岁比例", "60岁以上人数", "60岁以上比例" };
		String[] field = new String[] { "area", "totalPoorPeople", "avgAge", "lt16Count", "lt16Ratio", "ge16lt30Count",
				"ge16lt30Ratio", "ge30lt40Count", "ge30lt40Ratio", "ge40lt50Count", "ge40lt50Ratio", "ge50lt60Count",
				"ge50lt60Ratio", "ge60Count", "ge60Ratio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryAgeGroup(user, null, null, year,
				town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困人口年龄分组情况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困人口年龄分组情况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryWorkState(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		// 参数的初始化
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryWorkState(user, pageNo, pageSize, year, town, poverty);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportWorkState(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困人口", "乡镇内务工人数", "乡镇内务工比例", "县内务工人数", "县内务工比例", "省内务工人数",
				"省内务工比例", "省外务工人数", "省外务工比例" };
		String[] field = new String[] { "areaName", "totalPoorPeople", "townCount", "townRatio", "countyCount",
				"countyRatio", "inProvinceCount", "inProvinceCountRatio", "outProvinceCount", "outProvinceCountRatio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryWorkState(user, null, null, year,
				town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困人口务工状况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困人口务工状况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryWorkTime(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		// 参数的初始化
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryWorkTime(user, pageNo, pageSize, year, town, poverty);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportWorkTime(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困人口", "1个月人数", "1个月比例", "2个月人数", "2个月比例", "3个月人数", "3个月比例",
				"4个月人数", "4个月比例", "5个月人数", "5个月比例", "6个月人数", "6个月比例", "7个月人数", "7个月比例", "8个月人数", "8个月比例", "9个月人数",
				"9个月比例", "10个月人数", "10个月比例", "11个月人数", "11个月比例", "12个月人数", "12个月比例" };
		String[] field = new String[] { "areaName", "totalPoorPeople", "month1", "month1Ratio", "month2", "month2Ratio",
				"month3", "month3Ratio", "month4", "month4Ratio", "month5", "month5Ratio", "month6", "month6Ratio",
				"month7", "month7Ratio", "month8", "month8Ratio", "month9", "month9Ratio", "month10", "month10Ratio",
				"month11", "month11Ratio", "month12", "month12Ratio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryWorkTime(user, null, null, year,
				town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困人口务工时间情况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困人口务工时间情况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryInternalStudent(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryInternalStudent(user, pageNo, pageSize, year, town, poverty);
	}

	@Override
	public HSSFWorkbook exportInternalStudent(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困人口", "非在校生.人数", "非在校生.比例", "学前教育.人数", "学前教育.比例", "小学.人数",
				"小学.比例", "七年级.人数", "七年级.比例", "八年级.人数", "八年级.比例", "九年级.人数", "九年级.比例", "高中一年级.人数", "高中一年级.比例", "高中二年级.人数",
				"高中二年级.比例", "高中三年级.人数", "高中三年级.比例", "中职一年级.人数", "中职一年级.比例", "中职二年级.人数", "中职二年级.比例", "中职三年级.人数",
				"中职三年级.比例", "高职一年级.人数", "高职一年级.比例", "高职二年级.人数", "高职二年级.比例", "高职三年级.人数", "高职三年级.比例", "大专及以上.人数",
				"大专及以上.比例" };

		String[] field = new String[] { "areaName", "totalPoorPeople", "noStudentCount", "noStudentRatio", "xqjyCount",
				"xqjyRatio", "xiaoxueCount", "xiaoxueRatio", "7nianjiCount", "7nianjiRatio", "8nianjiCount",
				"8nianjiRatio", "9nianjiCount", "9nianjiRatio", "gaozhong1Count", "gaozhong1Ratio", "gaozhong2Count",
				"gaozhong2Ratio", "gaozhong3Count", "gaozhong3Ratio", "zhongzhi1Count", "zhongzhi1Ratio",
				"zhongzhi2Count", "zhongzhi2Ratio", "zhongzhi3Count", "zhongzhi3Ratio", "gaozhi1Count", "gaozhi1Ratio",
				"gaozhi2Count", "gaozhi2Ratio", "gaozhi3Count", "gaozhi3Ratio", "dazhuanCount", "dazhuanRatio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryInternalStudent(user, null, null,
				year, town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困人口在校生情况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困人口在校生情况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryPoorStatus(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryPoorStatus(user, pageNo, pageSize, year, town, poverty);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportPoorStatus(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困户数", "贫困人口", "一般贫困户.户数", "一般贫困户.比例", "低保贫困户.户数", "低保贫困户.比例",
				"五保贫困户.户数", "五保贫困户.比例", "一般贫困户.人数", "一般贫困户.比例", "低保贫困户.人数", "低保贫困户.比例", "五保贫困户.人数", "五保贫困户.比例" };
		String[] field = new String[] { "areaName", "totalHouseholds", "totalPoorPeople", "yiBanHouseholds",
				"yiBanHouseholdsRatio", "diBaoHouseholds", "diBaoHouseholdsRatio", "wuBaoHouseholds",
				"wuBaoHouseholdsRatio","yiBanPeopleCount","yiBanPeopleCountRatio", "diBaoPeopleCount", "diBaoPeopleCountRatio", "wuBaoPeopleCount",
				"wuBaoPeopleCountRatio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryPoorStatus(user, null, null, year,
				town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困户贫困人数统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困户贫困人数统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryMainPovertyCauses(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryMainPovertyCauses(user, pageNo, pageSize, year, town, poverty);
	}

	@Override
	public HSSFWorkbook exportMainPovertyCauses(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困户数", "因病户数", "因病比例", "因残户数", "因残比例", "因学户数", "因学比例", "因灾户数",
				"因灾比例", "缺土地户数", "缺土地比例", "缺水户数", "缺水比例", "缺技术户数", "缺技术比例", "缺劳力户数", "缺劳力比例", "缺资金户数", "缺资金比例",
				"交通条件落后户数", "交通条件落后比例", "自身发展力不足户数", "自身发展力不足比例" };
		String[] field = new String[] { "areaName", "poorFamilyCount", "illnessCount", "illnessRatio", "deformityCount",
				"deformityRatio", "studyCount", "studyRatio", "disasterCount", "disasterRatio", "landCount",
				"landRatio", "waterCount", "waterRatio", "technologyCount", "technologyRatio", "labourCount",
				"labourRatio", "capitalCount", "capitalRatio", "trafficCount", "trafficRatio", "developCount",
				"developRatio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryMainPovertyCauses(user, null,
				null, year, town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困户主要致贫原因情况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困户主要致贫原因情况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Pager queryOtherPovertyCauses(McUser user, Integer pageNo, Integer pageSize, String year, String town,
			String poverty) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		return (Pager) poorFaDao.queryOtherPovertyCauses(user, pageNo, pageSize, year, town, poverty);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportOtherPovertyCauses(McUser user, String year, String town, String poverty) {
		String[] cellName = new String[] { "序号", "地区", "贫困户数", "因病户数", "因病比例", "因残户数", "因残比例", "因学户数", "因学比例", "因灾户数",
				"因灾比例", "缺土地户数", "缺土地比例", "缺水户数", "缺水比例", "缺技术户数", "缺技术比例", "缺劳力户数", "缺劳力比例", "缺资金户数", "缺资金比例",
				"交通条件落后户数", "交通条件落后比例", "自身发展力不足户数", "自身发展力不足比例" };
		String[] field = new String[] { "areaName", "poorFamilyCount", "illnessCount", "illnessRatio", "deformityCount",
				"deformityRatio", "studyCount", "studyRatio", "disasterCount", "disasterRatio", "landCount",
				"landRatio", "waterCount", "waterRatio", "technologyCount", "technologyRatio", "labourCount",
				"labourRatio", "capitalCount", "capitalRatio", "trafficCount", "trafficRatio", "developCount",
				"developRatio" };

		year = StringUtil.isBlank(year) ? DateUtil.getYear(new Date()) : year;
		List<Map<String, Object>> result = (List<Map<String, Object>>) poorFaDao.queryOtherPovertyCauses(user, null,
				null, year, town, poverty);

		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("贫困户其他致贫原因情况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困户其他致贫原因情况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, result, field, cellStyle, true);
		return workbook;
	}

	@Override
	public List<PoorFamily> poorfamilies(Long id) {
		Map map = new HashMap<>();
		String hql = "from PoorFamily where id= :id ";
		map.put("id", id);
		return this.poorFaDao.queryList(hql, map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public HSSFWorkbook exportPoorFamilys(PoorFamily poorFamily, String name, String idNumber, String whether,String year,
			McUser user) {
		String[] cellName = new String[] { "序号", "户主姓名", "户主证件号码", "脱贫状态", "识别标准", "贫困户属性", "联系电话", "姓名", "单位名称",
				"单位隶属关系", "开始时间", "终止时间", "证件号码", "性别", "联系电话", "单位地址" };
		String[] field = new String[] { "name", "idNumber", "poverty", "standard", "attribute", "contact", "name2",
				"Unit_name", "Affiliation", "Prepared_time", "update_time", "ID_number", "sex", "telephone_number",
				"helpUnitName" };

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = getPager(poorFamily, sheetCount, 5000, name, idNumber, whether,year, user);
			excelResult.put(sheetCount, pager.getResultList());

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		List fList = new ArrayList<>();

		for (Object e : pager.getResultList()) {

			List<Family> family = ((PoorFamily) e).getFamily();
			List<HelpPerson> helpPersons = ((PoorFamily) e).getHelpPersons();
			Map map = new LinkedHashMap<>();
			map.put("poverty", ((PoorFamily) e).getPoverty());
			map.put("standard", ((PoorFamily) e).getStandard());
			map.put("attribute", ((PoorFamily) e).getAttribute());
			map.put("contact", ((PoorFamily) e).getContact());
			for (Family family2 : family) {
				/*
				 * Map map_2 = new LinkedHashMap<>(); map_2.put("name",
				 * family2.getName()); map_2.put("idNumber",
				 * family2.getIdNumber()); fList.add(map_2);
				 */
				if ("户主".equals(family2.getRelation())) {
					map.put("name", family2.getName());
					map.put("idNumber", family2.getIdNumber());
					// fList.add(map);
				}

			}

			if (helpPersons != null && helpPersons.size() > 0) {
				for (HelpPerson he : helpPersons) {
					map.put("name2", he.getName());
					map.put("Unit_name", he.getUnit_name());
					map.put("Affiliation", he.getAffiliation());
					map.put("Prepared_time", he.getPrepared_time());
					map.put("update_time", he.getUpdate_time());
					map.put("ID_number", he.getID_number());
					map.put("sex", he.getSex());
					map.put("telephone_number", he.getTelephone_number());
					map.put("helpUnitName", he.getHelpUnitName());
					fList.add(map);
					map = new LinkedHashMap<>(map);
				}
			} else {
				fList.add(map);
			}

		}

		HSSFWorkbook workbook = new HSSFWorkbook();

		/*
		 * VisitRecd a =(VisitRecd)pager.getResultList();
		 * a.getPoorFamily().getFamily().get(0).getName();
		 */
		// familyDao.queryList("select *from ");
		// 名字为贫困户户主姓名_走访记录.xls
		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("结对查询" + i);
			sheet.setDefaultColumnWidth(13);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "结对查询", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, fList, field, cellStyle, true);
		}

		return workbook;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<HelpPerson> queryFamilyhelpperson(Long id) {
		/*
		 * Map map = new HashMap<>(); String hql =
		 * "FROM  HelpPerson hp WHERE id IN (SELECT hb.helpPersonId FROM HELP_PERSON_AND_POOR_FAMILY hb WHERE hb.poorFamilyId = :id )"
		 * ; map.put("id", id); return this.poorFaDao.queryList(hql, map);
		 */
		// String sql="select * FROM HelpPerson hp WHERE id IN (SELECT
		// hb.helpPersonId FROM HELP_PERSON_AND_POOR_FAMILY hb WHERE
		// hb.poorFamilyId = :id )";
		List<HelpPerson> list = sessionFactory.getCurrentSession()
				.createSQLQuery(
						"select * from  helpperson hp where id IN (select hb.helpPersonId FROM help_person_and_poor_family hb where hb.poorFamilyId ="
								+ id + ")")
				.list();

		/*
		 * Map<Object,Object> map = new HashMap<>(); for (HelpPerson helpPerson
		 * : list) { map.put("name", helpPerson.getName()); map.put("unit_name",
		 * helpPerson.getUnit_name()); map.put("affiliation",
		 * helpPerson.getAffiliation()); map.put("Prepared_time",
		 * helpPerson.getPrepared_time()); map.put("update_time",
		 * helpPerson.getUpdate_time()); map.put("ID_number",
		 * helpPerson.getID_number()); map.put("sex", helpPerson.getSex());
		 * map.put("telephone_number", helpPerson.getTelephone_number());
		 * map.put("helpUnitName", helpPerson.getHelpUnitName());
		 * 
		 * }
		 */
		return list;
	}

	/**
	 * 贫困户人口规模统计
	 */
	@Override
	public Pager populationStatistics(McUser user, Integer pageNo, Integer pageSize, String year, String country,
			String village, String poverty) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 12 : pageSize;
		// 权限级别错误
		if (user.getUserLevel().getLevel() < 0 || user.getUserLevel().getLevel() > 5) {
			return new Pager(pageSize, pageNo, 0, null);
		}

		return poorFaDao.populationStatistics(user, pageNo, pageSize, year, country, village, poverty);
	}

	/**
	 * 贫困户人口规模统计excel导出
	 */
	@Override
	public HSSFWorkbook exportPopulationStatistics(McUser user, Integer pageNo, Integer pageSize, String year,
			String country, String village, String poverty) {

		String[] cellName = new String[] { "序号", "地区", "贫困户数", "户均转移性收入", "一人户户数", "一人户占比", "二人户户数", "二人户占比", "三人户户数",
				"三人户占比", "四人户户数", "四人户占比", "五人户户数", "五人户占比", "六人户（含）以上户数", "六人户（含）以上占比" };
		String[] field = new String[] { "area", "totalPoorFamily", "transferAVG", "oneCount", "onePercent", "twoCount",
				"twoPercent", "threeCount", "threePercent", "fourCount", "fourPercent", "fiveCount", "fivePercent",
				"sixCount", "sixPercent"};

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = populationStatistics(user, sheetCount, 5000, year, country, village, poverty);

			List list = new ArrayList<>();
			Map map = null;

			for (Map e : (List<Map>) pager.getResultList()) {
				map = new LinkedHashMap<>((Map) e.get("verbose"));
				map.put("totalPoorFamily", e.get("totalPoorFamily"));
				map.put("transferAVG", e.get("transferAVG"));
				map.put("area", e.get("area"));

				list.add(map);
			}
			excelResult.put(sheetCount, list);

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		HSSFWorkbook workbook = new HSSFWorkbook();

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("贫困户人口规模统计表" + i);
			sheet.setDefaultColumnWidth(22);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "贫困户人口规模统计表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, excelResult.get(i), field, cellStyle, true);
		}
		return workbook;
	}

	/**
	 * 贫困户党员情况统计
	 */
	@Override
	public Pager CPCStatistics(McUser user, Integer pageNo, Integer pageSize, String year, String country,
			String village, String poverty) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 12 : pageSize;
		// 权限级别错误
		if (user.getUserLevel().getLevel() < LevelUtil.ALL || user.getUserLevel().getLevel() > LevelUtil.VILLAGE) {
			return new Pager(pageSize, pageNo, 0, null);
		}

		return poorFaDao.CPCStatistics(user, pageNo, pageSize, year, country, village, poverty);
	}

	/**
	 * 贫困户党员情况统计excel导出
	 */
	@Override
	public HSSFWorkbook exportCPCStatistics(McUser user, Integer pageNo, Integer pageSize, String year, String country,
			String village, String poverty) {

		String[] cellName = new String[] { "序号", "地区", "贫困户数", "贫困人口", "有中共党员户数", "有中共党员户占比", "中共党员人数", "中共党员人数占比",
				"有预备中共党员户数", "有预备中共党员户占比", "预备中共党员人数", "预备中共党员人数占比" };
		String[] field = new String[] { "area", "totalPoorFamily", "totalPoor", "countCPCP", "percentCPCP", "totalCPCH",
				"percentCPCH", "countPreCPCP", "percentPreCPCP", "totalPreCPCH", "percentPreCPCH" };

		Integer sheetCount = 0;
		Pager pager = null;
		Map<Integer, List> excelResult = new HashMap<>();

		do {
			sheetCount++;
			pager = CPCStatistics(user, sheetCount, 5000, year, country, village, poverty);

			excelResult.put(sheetCount, pager.getResultList());

		} while (sheetCount < (pager.getRowCount() + 4999) / 5000);

		HSSFWorkbook workbook = new HSSFWorkbook();

		for (int i = 1; i <= excelResult.size(); i++) {
			HSSFSheet sheet = workbook.createSheet("贫困户党员情况统计表" + i);
			sheet.setDefaultColumnWidth(21);

			HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
			HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
			HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

			ExcelUtil.addTitle(sheet, cellName, "贫困户党员情况统计表", headStyle, columnTitleStyle);
			ExcelUtil.addContextByList(sheet, excelResult.get(i), field, cellStyle, true);
		}
		return workbook;
	}

	/**
	 * 贫困户帮扶责任人落实情况统计表
	 */
	@Override
	public Pager findFamilyLiable(McUser user, Integer pageNo, Integer pageSize, String year, String country,
			String village, String type) {
		pageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
		pageSize = pageSize == null || pageSize < 1 ? 120 : pageSize;
		// 权限错误,镇以下没有权限
		if (user.getUserLevel().getLevel() < 0 || user.getUserLevel().getLevel() > 4) {
			return new Pager(pageNo, pageSize, 0, new ArrayList<>(0));
		}

		// 镇级权限只能获取当前镇
		if (user.getUserLevel().getLevel() == 4) {
			Area area = user.getArea();
			if (area == null || area.getAreaCode().length() < 9) {
				return new Pager(pageNo, pageSize, 0, new ArrayList<>(0));
			}
			country = area.getAreaCode();
		}

		Pager page = poorFaDao.findFamilyLiable(user, pageNo, pageSize, year, country, village, type);

		return page;

	}

	/**
	 * 贫困户帮扶责任人落实情况统计表导出
	 */
	@Override
	public HSSFWorkbook exportFindFamilyLiable(McUser user, Integer pageNo, Integer pageSize, String year,
			String country, String village, String type) {

		String[] cellName = new String[] { "序号", "地区", "贫困户数", "落实帮扶责任人户数.户数", "落实帮扶责任人户数.比例" };
		String[] field = new String[] { "region", "total", "liable", "liableP" };

		List list = new ArrayList<>();
		Map map = null;

		for (Map e : (List<Map>) findFamilyLiable(user, pageNo, pageSize, year, country, village, type)
				.getResultList()) {
			map = new LinkedHashMap<>(30);
			if (e.get("verbose") != null) {
				map.putAll((Map) e.get("verbose"));
			}

			map.put("region", e.get("region"));// 地区

			list.add(map);
		}

		HSSFWorkbook workbook = new HSSFWorkbook();

		HSSFSheet sheet = workbook.createSheet("贫困户帮扶责任人落实情况统计表");
		sheet.setDefaultColumnWidth(19);

		HSSFCellStyle headStyle = ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle = ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle = ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet, cellName, "贫困户帮扶责任人落实情况统计表", headStyle, columnTitleStyle);
		ExcelUtil.addContextByList(sheet, list, field, cellStyle, true);
		return workbook;
	}

	@Override
	public Long addPoorFamilyHistofy(PoorFamilyHistory poorFamilyHistory) {
		return poorFaDao.addPoorFamilyHistofy(poorFamilyHistory);
	}

	@Override
	public PoorFamilyHistory getLatestPoorFamilyHistory(Long fid) {
		return poorFaDao.getLatestPoorFamilyHistory(fid);
	}

	@Override
	public PoorFamilyHistory getPoorFamilyHistory(Long id) {
		return poorFaDao.getPoorFamilyHistory(id);
	}

	/**
	 * 证件号重复记录统计
	 * @return
	 */
	@Override
	public Pager complexDuplicateIDNumberStatistics(Integer pageNo, Integer pageSize, String year, String country, McUser user) {
		Pager<?> pager = poorFaDao.complexQueryDuplicateIDStatistics(pageNo, pageSize, year, country, user);
	
		return pager;
	}

	/**
	 * 证件号重复记录统计excel导出
	 * @return
	 */
	@Override
	public HSSFWorkbook complexExportDuplicateIDNumberStatistics(int pageNo, int pageSize, String year, String country, McUser user) {
		String[] cellName = new String[] { "序号", "地区", "证件号码重复数量"};
		String[] field = new String[] { "region","povertyVillages"};
		
		List list  = new ArrayList<>();
		for(Map e : (List<Map>)(complexDuplicateIDNumberStatistics(pageNo, pageSize, year, country, user)).getResultList()) {
			list.add(e);
		}
		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet("证件号码重复统计表");
		sheet.setDefaultColumnWidth(26);
		
		HSSFCellStyle headStyle =  ExcelUtil.getTitleStyle(workbook);
		HSSFCellStyle cellStyle =  ExcelUtil.getCellStyle(workbook);
		HSSFCellStyle columnTitleStyle =  ExcelUtil.getColumnTitleStyle(workbook);

		ExcelUtil.addTitle(sheet,cellName,"证件号码重复统计表",headStyle,columnTitleStyle);
		ExcelUtil.addContextByList(sheet, list, field, cellStyle, true);
		
		return workbook;
	}

	/**
	 * 根据户编号查找
	 * @return
	 */
	@Override
	public List<PoorFamily> getPoorFamilyByNumber(String number) {
		String annual = ApplicationProperties.getAnnual();
		Map<String,String> condition = Collections.generateHashMap("number",number);
		return poorFaDao.queryList(" from PoorFamily where isDel='0' and annual = '"+ annual +"' and number = :number",condition);
	}

	@Override
	public List<PoorFamily> getPoorFamilyByAreaID(Long id) {
		return poorFaDao.queryList(" from PoorFamily where isDel='0' and area.id="+id+" and annual= '"+ ApplicationProperties.getAnnual() +"'", null);
	}

    @Override
    public Long getPoorFamilyCount(String annual,Long areaID) {
        return (Long) poorFaDao
                .queryList(" select count(*) from PoorFamily where isDel='0' and annual= :annual and area.id=:areaID",Collections.generateHashMap("annual",annual,"areaID",areaID))
                .get(0);
    }

	@Override
	public List findPoorFamilyByVillageId(Long villageId) {
		
		return null;
	}

	@Override
	public Pager findPoorFamilyByCondition(Integer pageNo, Integer pageSize, String country, String village ,String poorName ,String poorFamilyNum) {
		Map map = new HashMap<>();
		StringBuffer sql = new StringBuffer();
		String field = " select p.id as id ,p.country as country ,p.village as village, p.number as number ,f.id as familyId ,f.name as name ,f.ID_NUMBER as idNumber,f.RELATION relation ";
		sql.append(" FROM poor_family p join family f on p.id = f.fid join vision_pool_family vpf on vpf.pool_family_id=p.id  WHERE p.IS_DEL= '0' and f.IS_DEL='0' ");
		
		if(StringUtil.isNotBlank(country)){
			sql.append(" and p.country = '").append(country).append("' ");
		}
		
		if(StringUtil.isNotBlank(village)){
			sql.append(" and p.village = '").append(village).append("' ");
		}
		
		if(StringUtil.isNotBlank(poorFamilyNum)){
			sql.append(" and p.NUMBER like '%").append(poorFamilyNum).append("%' ");
		}
		// 姓名
		if (StringUtil.isNotBlank(poorName)) {
			//hql.append(" AND id in (SELECT fid FROM family WHERE IS_DEL='0' and  NAME LIKE '%" + poorName + "%') ");
			sql.append(" and f.NAME LIKE '%" + poorName + "%'");
		}
		
		sql.append("ORDER BY p.poverty,p.number");
		//Pager<PoorFamily> page = poorFaDao.getPagerByHql(pageNo, pageSize, sql.toString(), map);
		
		int count = poorFaDao.getCount("select count(*)"+sql.toString(),map);
		
		List<PoorFamilyVo> list = poorFaDao.getPoorFamilyVo(pageNo,pageSize,field+sql.toString(),map);
		
		Pager pager = new Pager<>(pageSize, pageNo, count, list);
		
//		List<PoorFamilyVo> result = new ArrayList<>();
//		List<Family> families = null;
//		Pager<PoorFamilyVo> newPager = null;
//		newPager.setPageNo(pageNo);
//		newPager.setPageSize(pageSize);
//		newPager.setRowCount(page.getRowCount());
//		newPager.setPageCount(page.getPageCount());
//		newPager.setPageSizeList(page.getPageSizeList());
		
//		if(StringUtil.isNotBlank(poorName)){
//			for (PoorFamily pf : page.getResultList()) {
//				PoorFamilyVo tempVo = new PoorFamilyVo();
//				families = new ArrayList<>();
//				
//				tempVo.setId(pf.getId());
//				tempVo.setProvince(pf.getProvince());
//				tempVo.setCity(pf.getCity());
//				tempVo.setCounty(pf.getCounty());
//				tempVo.setCountry(pf.getCountry());
//				
//				
//				for (Family f : pf.getFamily()) {
//					if("0".equals(f.getIsDel()) && poorName.equalsIgnoreCase(f.getName())){
//						//families.add(f);
//						tempVo.setFamilyId(f.getId());
//						tempVo.setName(f.getName());
//						tempVo.setIdNumber(f.getIdNumber());
//						tempVo.setRelation(f.getRelation());
//						
//					}
//				}
//				//BeanUtils.copyProperties(pf,tempPF);
//				//tempPF.setFamily(families);
//				result.add(tempVo);
//			}
//			page.setResultList(result);
//		}
//		
		
/*		List<PoorFamily> result = new ArrayList<>();
		List<Family> families = null;
		
		if(StringUtil.isNotBlank(poorName)){
			for (PoorFamily pf : page.getResultList()) {
				PoorFamily tempPF = new PoorFamily();
				families = new ArrayList<>();
				for (Family f : pf.getFamily()) {
					if("0".equals(f.getIsDel()) && poorName.equalsIgnoreCase(f.getName())){
						families.add(f);
					}
				}
				BeanUtils.copyProperties(pf,tempPF);
				tempPF.setFamily(families);
				result.add(tempPF);
			}
			page.setResultList(result);
		}
*/		
		
		
		
		return pager;
	}

	@Override
	public PoorFamily getPoorFamilyByNumberAndAnnual(String number, String annual) {
		Map<String,String> condition = Collections.generateHashMap("number",number);
		List list = poorFaDao.queryList(" from PoorFamily where isDel='0' and annual = '"+ annual +"' and number = :number",condition);
		if(list!=null && list.size()>0){
			return (PoorFamily) list.get(0);
		}
		return null;
	}
}
